<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 250px;
            height: 50px;
            border: 1px solid pink;
            line-height: 50px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div></div>

    <script>
        const divv = document.querySelector('div')
        const date = new Date()
        function dateTime (){
            //获取时分秒 
            let h = date.getHours()
            let f = date.getMinutes()
            let m = date.getSeconds()
            h = h<10? '0'+h:h
            f = f<10? '0'+f:f
            m = m<10? '0'+m:m
            return `今天是${date.getFullYear()}年${date.getMonth()+1}月${date.getDate()}日 ${h}:${f}:${m}`
        }

        //在浏览器直接显示 今日时间
        divv.innerHTML = dateTime()

        // 添加定时器
        setInterval(dateTime, 1000);
    </script>
</body>
</html>